package gitee.derumin.lib_for_derumin.helpers.config.configserializers;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.block.Block;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;

public class BlockSerializer implements ConfigFieldSerializer<Block> {
    @Override
    public Block jsonToObject(JsonElement element, String name) {
        return Registries.BLOCK.get(Identifier.tryParse(JsonHelper.asString(element, name)));
    }

    @Override
    public JsonElement objectToJson(Object contains) {
        return new JsonPrimitive(Registries.BLOCK.getId((Block) contains).toString());
    }
}
